package crm.implementor;



import crm.daoInterfaces.CustomerInfoDao;
import crm.dbhandelling.Crude;
import crm.model.CustomerInfo;


public class CustomerInfoImp extends Crude implements CustomerInfoDao
{

	private String className= new CustomerInfo().getClass().getName();	
	@Override
	public void add(CustomerInfo cat)throws Exception
	{
		super.insert(cat);
	}

	@Override
	public void update(CustomerInfo cat) {
		
		super.update(className, "name",cat.getName(), "customerId", cat.getAutoCustomerId()+"");
		super.update(className, "address",cat.getAddress(), "customerId", cat.getAutoCustomerId()+"");
		super.update(className, "company",cat.getCompany(), "customerId", cat.getAutoCustomerId()+"");
		super.update(className, "emailAdr",cat.getEmailAdr(), "customerId", cat.getAutoCustomerId()+"");
		super.update(className, "phone",cat.getPhone()+"", "customerId", cat.getAutoCustomerId()+"");
		
	}

	@Override
	public void delete(CustomerInfo cat) {
		this.delete(className,"customerId", cat.getAutoCustomerId()+"");
		
	}

	

	@Override
	public CustomerInfo[] retrieveAll() throws Exception {
		

		Object[] att=super.retreiveAll(className);
		CustomerInfo[] s=new CustomerInfo[att.length];
		for(int i=0;i<s.length;i++)
				s[i]=(CustomerInfo) att[i];
		return s;
		
	}

	@Override
	public int getAutoGenratedKey()
	  {
		 int key=super.getAutoGenratedKey(className,"autocustomerId") ;
		 return key;
	  }

	@Override
	public CustomerInfo retrieve(String conditionField,
			String conditionValue) throws Exception {
		
		CustomerInfo c=(CustomerInfo) super.retreive(className, conditionField, conditionValue);
		return c;
	}

	@Override
	public CustomerInfo[] retrieveArray(String conditionField, String conditionValue) throws Exception {
		
		Object[] att=super.retreiveArrayOnCondition(className, conditionField, conditionValue);
		CustomerInfo[] s=new CustomerInfo[att.length];
		for(int i=0;i<s.length;i++)
				s[i]=(CustomerInfo) att[i];
		return s;
		
	}

	

	

	
}
